package com.raincat.tools.permissiontools;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Build;

/**
 * <pre>
 *     author : RainCat
 *     org    : Shenzhen JingYu Network Technology Co., Ltd.
 *     e-mail : nining377@gmail.com
 *     time   : 2020/05/13
 *     desc   : 获取权限
 *     version: 1.0
 * </pre>
 */
public class PermissionConfig {
    /**
     * 存储卡访问
     */
    public static String PERMISSION_EXTERNAL_STORAGE = Manifest.permission.READ_EXTERNAL_STORAGE;
    /**
     * 存储卡访问
     */
    public static String PERMISSION_EXTERNAL_STORAGE2 = Manifest.permission.WRITE_EXTERNAL_STORAGE;
    /**
     * 相机
     */
    public static String PERMISSION_CAMERA = Manifest.permission.CAMERA;
    /**
     * 读取联系人
     */
    public static String PERMISSION_READ_CONTACTS = Manifest.permission.READ_CONTACTS;
    /**
     * 定位
     */
    public static String PERMISSION_ACCESS_FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION;
    /**
     * 拨打电话
     */
    public static String PERMISSION_CALL_PHONE = Manifest.permission.CALL_PHONE;
    /**
     * 麦克风
     */
    public static String PERMISSION_MICROPHONE = Manifest.permission.RECORD_AUDIO;

    public static void checkPermission(Context context, String dialogMessage, String[] permissions, PermissionProxyListener permissionProxyListener) {
        PermissionProxyListenerManager.getInstance().setPermissionProxyListenerListener(permissionProxyListener);
        Intent intent = new Intent(context, PermissionProxyActivity.class);
        intent.putExtra("message", dialogMessage);
        intent.putExtra("permissions", permissions);
        context.startActivity(intent);
        ((Activity) context).overridePendingTransition(0, 0);
    }

    public static void checkInstallPermission(final Context context, String dialogMessage, String url, final PermissionProxyListener permissionProxyListener) {
        if (url.endsWith(".apk") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !context.getPackageManager().canRequestPackageInstalls()) {
            PermissionProxyListenerManager.getInstance().setPermissionProxyListenerListener(permissionProxyListener);
            Intent intent = new Intent(context, PermissionProxyActivity.class);
            intent.putExtra("message", dialogMessage);
            intent.putExtra("url", url);
            context.startActivity(intent);
            ((Activity) context).overridePendingTransition(0, 0);
        } else
            permissionProxyListener.onPermissionGet(true);
    }
}
